<?php
namespace app\admin\controller;
use app\admin\model\Wxconfig;

class Wx extends Base
{
    /**
     * 
     * 微信配置
     * @return \think\response\View
     */
    public function index()
    {
        $wx = new Wxconfig();
        $list = $wx->find();
        $this->assign('list',$list);
        return view();
    }

    /**
     * 保存微信配置
     */
    public function saveConfig()
    {
        $data = input();
        $wx = D('Wxconfig');
        $rel = $wx->find();
        if($rel) {
            //则更新
            $item['id'] = $rel['id'];
            $item['appid'] = $data['cwxappid'];
            $item['appsecret'] = $data['cwxappsecret'];
            $item['mchid'] = $data['cwxmchid'];
            $item['keys'] = $data['cwxappkey'];
            $wx->update($item);
        }else {
            //则新增
            $item['appid'] = $data['cwxappid'];
            $item['appsecret'] = $data['cwxappsecret'];
            $item['mchid'] = $data['cwxmchid'];
            $item['keys'] = $data['cwxappkey'];
            $wx->insert($item);
        }
            $this->redirect('Wx/index');
    }
}
